package cn.vcjf.weapp.api.user.controller;


import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.user.entity.UserWallet;
import cn.vcjf.weapp.api.user.service.UserWalletService;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Controller
@RequestMapping("/user/userWallet")
public class UserWalletController {
	@Resource
	private UserWalletService userWalletService;

	@RequestMapping("/addUserWallet")
	@ResponseBody
	public TableResult addUserWallet(UserWallet userWallet) {
		userWallet.preInsert();
		boolean b = userWalletService.insert(userWallet);
		return TableResult.Result(b);
	}

	@RequestMapping("/doUserWithdraw")
	@ResponseBody
	public TableResult doUserWithdraw(UserWallet userWallet) {

		boolean b = userWalletService.doUserWithdraw(userWallet);
		return TableResult.Result(b);
	}

	@RequestMapping("/findUserWalletOne")
	@ResponseBody
	public TableResult findUserWalletOne(UserWallet userWallet) {

		EntityWrapper<UserWallet> wrapper = userWallet.getQueryWrapper();

		UserWallet result = userWalletService.selectOne(wrapper);

		return TableResult.OKResult(result);
	}

	@RequestMapping("/findUserWalletList")
	@ResponseBody
	public TableResult findUserWalletList(UserWallet userWallet) {

		EntityWrapper<UserWallet> wrapper = userWallet.getQueryWrapper();

		Page<UserWallet> page = userWallet.getPageInfo();

		page = userWalletService.selectPage(page, wrapper);

		return TableResult.OKResult(page);

	}

	@RequestMapping("/deleteUserWallet")
	@ResponseBody
	public TableResult deleteUserWallet(UserWallet userWallet) {
		userWallet.preUpdate();
		boolean b = userWalletService.deleteById(userWallet.getId());
		return TableResult.Result(b);
	}

}
